package main

import (
	"bufio"
	"log"
	"os"
	"regexp"
	"strconv"
	"strings"
)

func main() {
	log.Println("读取文件开始")
	// 打开输入文件
	file, err := os.Open("/Users/suntao/Project/alipayDmp/oppoShow/showTimeOutForOppo.log")
	//file, err := os.Open("/Users/suntao/Project/alipayDmp/oppoShow/oppo曝光超时.log")
	if err != nil {
		log.Println("嘎嘎:", err.Error())
		return
	}
	defer file.Close()

	// 使用带缓冲的读取器
	reader := bufio.NewReaderSize(file, 1024*1024)
	count := 0
	for {
		line, err := reader.ReadString('\n')
		if err != nil {
			// 判断是否到达文件结尾
			if err.Error() == "EOF" {
				break
			}
		}
		line = strings.ReplaceAll(line, "\n", "")
		timeStr := extractExposureTimeoutNumber(line)
		time, err := strconv.Atoi(timeStr)
		if err != nil {
			log.Println("conv err:", err.Error())
		}
		if time <= 24*3600 {
			count++
			log.Println(time)
		}
	}
	log.Println("总数：", count)
}

func extractExposureTimeoutNumber(logLine string) string {
	// 定义正则表达式来匹配曝光超时后面的数字
	regex := regexp.MustCompile(`曝光超时:(\d+)`)
	match := regex.FindStringSubmatch(logLine)

	if len(match) >= 2 {
		return match[1]
	}

	return ""
}
